package 贪心;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @ClassName _452用最少量的箭引爆气球
 * @Description TODO
 * @Author 昝亚杰
 * @Date 2021/12/25 20:21
 * Version 1.0
 **/
public class _452用最少量的箭引爆气球 {
//    public static void main(String[] args) {
//        int[][] a = {{1,1},{2,1},{0,2}};
//        findMinArrowShots(a);
//        for(int aa[] : a){
//            System.out.println(aa[0]);
//        }
//    }
    public static int findMinArrowShots(int[][] points) {
        int count = 1;
        Arrays.sort(points, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return Integer.compare(o1[0],o2[0]);
            }
        });
        for(int i = 1; i < points.length; i++){
            if(points[i][0] > points[i - 1][1]){
                count++;
            }else{
                points[i][1] = Math.min(points[i - 1][1],points[i][1]);
            }
        }
        return count;
    }
}
